﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Security.AccessControl;

namespace SharpGameLibrary
{
    public static class Methods
    {
        public static Tuple<int, int> createTuple(Object obj)
        {
            Match matchNumbers = Regex.Match(obj.ToString(), @"(\d), (\d)");

            int x = Convert.ToInt32(matchNumbers.Groups[1].Value);
            int y = Convert.ToInt32(matchNumbers.Groups[2].Value);

            var tuple = Tuple.Create(x, y);

            return tuple;
        }

        public static Graphics toGraphics(this Image image,
            System.Drawing.Drawing2D.CompositingQuality compositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed,
            System.Drawing.Drawing2D.SmoothingMode smoothingMode = System.Drawing.Drawing2D.SmoothingMode.None,
            System.Drawing.Drawing2D.InterpolationMode interpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor)
        {
            Graphics g = Graphics.FromImage(image);

            g.CompositingQuality = compositingQuality;
            g.SmoothingMode = smoothingMode;
            g.InterpolationMode = interpolationMode;

            return g;
        }

        public static void setAccessRule(string directory)
        {
            System.Security.AccessControl.DirectorySecurity sec = System.IO.Directory.GetAccessControl(directory);

            FileSystemAccessRule accRule = new FileSystemAccessRule(Environment.UserDomainName + "\\" + Environment.UserName,
                FileSystemRights.FullControl, AccessControlType.Allow);

            sec.AddAccessRule(accRule);
        }
    }
}
